<template>
	<view class="all-main">
		<view class="main">
			<u-sticky>
				<view class="search">
					<view class="search-input">
						<u-search placeholder="终端号" shape="square" bgColor="#ffffff" :showAction="false" v-model="keyword"></u-search>
					</view>
					<view class="search-product" @click="productShow = true">
						<text>{{productName}}</text>
						<u-icon name="list-dot" color="#2979ff" size="24"></u-icon>
					</view>
				</view>
				<view class="state-tag">
					<u-subsection :list="stateList" mode="subsection" :current="state" @change="sectionChange"></u-subsection>
				</view>
			</u-sticky>
			<view v-if="lists.length > 0" class="lists">
				<view v-for="(item, index) in lists" :key="index" class="items">
					<view class="titles">
						<view class="sn">
							<text v-if="item.terminal.merchant_name">{{item.terminal.merchant_name}}</text>
						</view>
						<view class="standard-state">
							<text v-if="item.state==1" class="warms">进行中</text>
							<text v-else-if="item.state==3" class="reds">未达标</text>
							<text v-else class="greens">已达标</text>
						</view>
					</view>
					<view class="merchant-info">
						<view>
							<text v-if="item.terminal.name" style="padding-right: 10rpx;">{{item.terminal.name}} /</text>
							<text>{{item.sn}}</text>
						</view>
					</view>
					<view v-if="item.terminal.bind_time" class="merchant-info">
						<view class="lefts">
							<text>入网时间</text>
						</view>
						<view class="rights">
							<text>{{item.terminal.bind_time}}</text>
						</view>
					</view>
					<view v-if="item.details.length > 0" class="standard-list">
						<view v-for="(items, indexs) in item.details" :key="indexs" class="standard-item">
							<view class="standard-info">
								<view class="standard-info-top">
									<view class="days">
										<text v-if="items.start_day==0 || items.start_day==30">{{items.start_day+1}}</text>
										<text v-else>{{items.start_day}}</text>
										<text class="tags"> ~ </text>
										<text>{{items.end_day}}</text>
										<text class="units">(天)</text>
									</view>
									<view class="trades">
										<text class="reds">{{items.trade_money*100 >= items.money*100 ? items.money*100/100 : items.trade_money*100/100}}</text>
										<text class="tags">|</text>
										<text class="greens">{{items.money*100/100}}</text>
									</view>
									<view class="state-icon">
										<u-icon v-if="items.state != 2" name="close-circle" color="#fa3534" size="20"></u-icon>
										<u-icon v-else name="checkmark-circle" color="#19be6b" size="20"></u-icon>
									</view>
								</view>
								<view class="standard-info-bottom">
									<text>{{items.start_time}}</text>
									<text>~</text>
									<text>{{items.end_time}}</text>
									<text v-if="items.sort < 3" style="padding-left: 10rpx; color: #fa3534;">【贷记卡】</text>
									<text v-else style="padding-left: 10rpx; color: #fa3534;">【贷记卡、扫码】</text>
									<text>交易</text>
									<text>{{items.money*100/100}}</text>
									<text>，奖励</text>
									<text>{{items.cash_money*100/100}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<u-empty v-else mode="list" icon="/static/Empty/data_null.png">
			</u-empty>
			<u-picker :show="productShow" :columns="productList" keyName="title" @confirm="proConfirm"
				@cancel="productShow = false"></u-picker>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '',
				stateList: ['进行中', '已达标', '未达标'],
				state: 0,
				page: 1,
				page_size: 10,
				bottom: true,
				lists: [],
				productShow: false,
				productList: [],
				product_id: '',
				productName: '全部',
			}
		},
		onLoad() {
			this.loadData()
			this.getHzyProduct()
		},
		filters: {
			formatDate(value) {
				if (value) {
					return new Date(value * 1000).toLocaleString(); // 转换为本地日期和时间字符串
				}
			}
		},
		//上拉加载
		onReachBottom() {
			if (this.bottom == true) {
				this.page += 1
				this.loadData()
			}
		},
		methods: {
			// 状态选择
			sectionChange(index) {
				if (this.state != index) {
					this.state = index
					this.page = 1
					this.bottom = true
					this.lists = []
					this.loadData()
				}
			},
			// 产品选择
			proConfirm(e) {
				if (this.product_id != e.value[0].id) {
					this.product_id = e.value[0].id
					this.productName = e.value[0].title
					this.productShow = false
					this.page = 1
					this.bottom = true
					this.lists = []
					this.loadData()
				} else {
					this.productShow = false
				}
			},
			// 获取产品
			async getHzyProduct() {
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyProduct',
				});
				if (res.code == 200) {
					this.productList = [res.data]
				}
			},
			// 加载数据
			async loadData() {
				uni.showLoading({
					title: '加载中'
				});
				const {
					data: res
				} = await this.$myHttp({
					url: 'v1/getHzyStandardList',
					data: {
						page_size: 15,
						page: this.page,
						keyword: this.keyword,
						state: this.state,
						product_id: this.product_id
					},
				});
				uni.hideLoading()
				if (res.code == 200) {
					if (res.data.data !== undefined && res.data.data !== null && res.data.data.length >
						0) {
						if (this.page == 1) {
							this.lists = res.data.data
						} else {
							this.lists = [...this.lists, ...res.data.data]
						}
						this.display = true
					} else {
						this.bottom = false
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.all-main {
		.main {
			.search {
				padding: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #F2F6FC;
				
				.search-input {
					width: 70%;
				}
				
				.search-product {
					width: 30%;
					display: flex;
					justify-content: flex-end;
					align-items: center;
					font-size: 24rpx;
					
					text {
						padding-right: 10rpx;
					}
				}
			}
			
			.state-tag {
				padding: 0 30rpx 30rpx 30rpx;
				background-color: #F2F6FC;
			}
			
			.lists {
				padding: 0 30rpx;
				
				.items {
					background-color: #ffffff;
					border-radius: 16rpx;
					box-shadow: 7px 0px 30px -18px #888888;
					margin-bottom: 30rpx;
					
					.titles {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 30rpx;
						border-bottom: 1px solid #F2F6FC;
						
						.sn {
							font-weight: bold;
							font-size: 28rpx;
						}
						
						.standard-state {
							width: 18%;
							text-align: right;
							font-size: 28rpx;
							font-weight: bold;
						}
					}
					
					.reds {
						color: #fa3534;
					}
					
					.greens {
						color: #19be6b;
					}
					
					.warms {
						color: #ff9900;
					}
					
					.merchant-info {
						display: flex;
						justify-content: space-between;
						align-items: center;
						padding: 20rpx 30rpx 0 30rpx;
						font-size: 28rpx;
						
						.lefts {
							width: 25%;
						}
						
						.rights {
							color: #909399;
						}
					}
					
					.standard-list {
						margin-top: 30rpx;
						padding: 0 30rpx;
						padding-bottom: 30rpx;
						border-top: 1px solid #F2F6FC;
						
						.standard-item {
							margin-top: 20rpx;
							border: 1px dashed #F2F6FC;
							padding: 20rpx;
							
							.standard-titles {
								padding-bottom: 20rpx;
								display: flex;
								border-bottom: 1px dashed #F2F6FC;
								justify-content: space-between;
							}
							
							.standard-info {
								
								.standard-info-top {
									display: flex;
									align-items: center;
									
									.days {
										width: 25%;
									}
									
									.trades {
										width: 65%;
										display: flex;
										justify-content: flex-end;
										align-items: center;
										
										.tags {
											margin-top: -8rpx;
										}
									}
									
									.state-icon {
										padding-top: 4rpx;
										width: 10%;
										display: flex;
										justify-content: flex-end;
									}
									
									.tags {
										padding: 0 8rpx;
										color: #909399;
									}
									
									.units {
										font-size: 24rpx;
										color: #909399;
									}
								}
								
								.standard-info-bottom {
									border-top: 1px dashed #F2F6FC;
									font-size: 24rpx;
									margin-top: 10rpx;
									padding-top: 10rpx;
									color: #909399;
								}
							}
						}
					}
				}
			}
		}
	}
</style>
